import { ViewTool } from '@/utils';

/**
 * PIM 部件模型
 *
 * @export
 * @class PIMModel
 */
export default class PIMModel {

    /**
     * 菜单项集合
     *
     * @private
     * @type {any[]}
     * @memberof PIMModel
     */
    private items: any[] = [
                {
        	id: '74769e4fae4abae779fa5e1d71bef05d',
        	name: 'user_menus',
        	text: '用户菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '用户菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: '5b9d13aef24ebeec49af943db98b35cb',
                	name: 'menuitem3',
                	text: '设置',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '设置',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-cog',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
        	],
        }
        ,
                {
        	id: '3191ef144a2b66a82edce66de7461bd5',
        	name: 'top_menus',
        	text: '顶部菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '顶部菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: 'A8D78DD5-209F-4ADF-8B05-72F646DFCECD',
                	name: 'menuitem1',
                	text: '-',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '-',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: '',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
        	],
        }
        ,
                {
        	id: 'dfc129d27761fa5213b01cda5ee15778',
        	name: 'left_exp',
        	text: '左侧菜单',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '左侧菜单',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        	items: [
                		        {
                	id: 'F174B1DB-8E40-44BD-A1F9-4C58915A8375',
                	name: 'menuitem19',
                	text: '首页',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '首页',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-university',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                }
                ,
                		        {
                	id: '1F73FB8E-0E2A-4B7A-B800-004B01AB2301',
                	name: 'menuitem5',
                	text: '基础',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '基础',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-users',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: '4b24bf3dc681c591cb1663ce8853cc32',
                        	name: 'menuitem15',
                        	text: '员工',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '员工',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-user',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_5',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hremployee-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '9EAF638F-4BD3-41E5-95D9-D0BB5A0F8375',
                        	name: 'menuitem8',
                        	text: '合同',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '合同',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-th-large',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_11',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrcontract-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '7A36C06F-4B6F-4479-8D8C-7CA6FCF0FB70',
                        	name: 'menuitem16',
                        	text: '档案',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '档案',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-newspaper-o',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_12',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrarchives-v-006',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '2839792B-0F2D-44D7-ADEB-6A30C89445DE',
                        	name: 'menuitem17',
                        	text: '职称',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '职称',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-shirtsinbulk',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_7',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrtechnical-title-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '05C5F292-8A81-448B-81EF-53527DFCA207',
                        	name: 'menuitem18',
                        	text: '证书',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '证书',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-certificate',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_9',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrcertificate-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
                		        {
                	id: 'B25E7335-DEBD-478A-81FD-1BB47B68DFA4',
                	name: 'menuitem2',
                	text: '组织',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '组织',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-sitemap',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: '98B816C8-2AA6-4BB4-9CC5-C2B72A61C24B',
                        	name: 'menuitem4',
                        	text: '法人',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '法人',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-shirtsinbulk',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_3',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrlegal-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '7950AF8B-457E-4B66-9E43-48FA95ED5A0C',
                        	name: 'menuitem6',
                        	text: '运营单位',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '运营单位',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-building-o',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_4',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hroperation-unit-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '8BCD342D-9983-4932-85AF-C31662BCE75A',
                        	name: 'menuitem7',
                        	text: '组织层次结构',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '组织层次结构',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-signal',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_14',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hromhierarchy-cat-grid-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: 'F4927234-CF7B-44BA-AECC-24318EF8B794',
                        	name: 'menuitem9',
                        	text: '所有组织',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '所有组织',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-sitemap',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_13',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrorganization-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
                		        {
                	id: 'E065C1FE-A872-4209-A254-67DE568A5F43',
                	name: 'menuitem10',
                	text: '职位',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '职位',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-server',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: 'F40EFB9B-4A24-45F2-8CD1-BD9CFD890109',
                        	name: 'menuitem11',
                        	text: '职位',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '职位',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-delicious',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_8',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrpost-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '5866C16B-4C55-4E2C-8229-15F7533B9E4F',
                        	name: 'menuitem12',
                        	text: '职务',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '职务',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-bars',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_6',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrduty-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
                		        {
                	id: 'CF53A596-B20F-4955-8166-98152FA63732',
                	name: 'menuitem13',
                	text: '调动',
                	type: 'MENUITEM',
                	counterid: '',
                	tooltip: '调动',
                	expanded: false,
                	separator: false,
                	hidden: false,
                	hidesidebar: false,
                	opendefault: false,
                	iconcls: 'fa fa-pencil-square',
                	icon: '',
                	textcls: '',
                	appfunctag: '',
                	resourcetag: '',
                	items: [
                        		        {
                        	id: 'A9D45433-F1E3-434B-A257-60E9799540EE',
                        	name: 'menuitem14',
                        	text: '调动申请',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '调动申请',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-cube',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_15',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrtransfer-apply-tab-exp-view',
                        	resourcetag: '',
                        }
                        ,
                        		        {
                        	id: '5840477A-566C-4CB5-9109-51ACC293DFBE',
                        	name: 'menuitem20',
                        	text: '调动管理',
                        	type: 'MENUITEM',
                        	counterid: '',
                        	tooltip: '调动管理',
                        	expanded: false,
                        	separator: false,
                        	hidden: false,
                        	hidesidebar: false,
                        	opendefault: false,
                        	iconcls: 'fa fa-male',
                        	icon: '',
                        	textcls: '',
                        	appfunctag: '_2',
                        	appfuncyype: 'APPVIEW',
                        	viewname: 'hrtransfer-apply-wfdyna-exp-grid-view',
                        	resourcetag: '',
                        }
                        ,
                	],
                }
                ,
        	],
        }
        ,
                {
        	id: 'fec63a28f5d99fd4ac7e43004b6a16f8',
        	name: 'bottom_exp',
        	text: '底部内容',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部内容',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '5055aa1daf0c26ad0615bf59b899dac6',
        	name: 'footer_left',
        	text: '底部左侧',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部左侧',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '543d8997967e967da007eba50c2c8ba1',
        	name: 'footer_center',
        	text: '底部中间',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部中间',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
                {
        	id: '6afec0593769e90bdf8be1d490367306',
        	name: 'footer_right',
        	text: '底部右侧',
        	type: 'MENUITEM',
        	counterid: '',
        	tooltip: '底部右侧',
        	expanded: false,
        	separator: false,
        	hidden: false,
        	hidesidebar: false,
        	opendefault: false,
        	iconcls: '',
        	icon: '',
        	textcls: '',
        	appfunctag: '',
        	resourcetag: '',
        }
        ,
    ];

	/**
	 * 应用功能集合
	 *
	 * @private
	 * @type {any[]}
	 * @memberof PIMModel
	 */
	private funcs: any[] = [
        {
            appfunctag: '_4',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hroperationunitgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hroperationunits/:hroperationunit?/gridview/:gridview?',
            parameters: [
                { pathName: 'hroperationunits', parameterName: 'hroperationunit' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_12',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrarchivesv_006',
            deResParameters: [],
            routepath: '/pim/:pim?/hrarchives/:hrarchives?/v_006/:v_006?',
            parameters: [
                { pathName: 'hrarchives', parameterName: 'hrarchives' },
                { pathName: 'v_006', parameterName: 'v_006' },
            ],
        },
        {
            appfunctag: '_8',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrposttabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrposts/:hrpost?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hrposts', parameterName: 'hrpost' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
        {
            appfunctag: '_14',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hromhierarchycatgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hromhierarchycats/:hromhierarchycat?/gridview/:gridview?',
            parameters: [
                { pathName: 'hromhierarchycats', parameterName: 'hromhierarchycat' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_6',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrdutygridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrduties/:hrduty?/gridview/:gridview?',
            parameters: [
                { pathName: 'hrduties', parameterName: 'hrduty' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_13',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrorganizationgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrorganizations/:hrorganization?/gridview/:gridview?',
            parameters: [
                { pathName: 'hrorganizations', parameterName: 'hrorganization' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_2',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrtransferapplywfdynaexpgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrtransferapplies/:hrtransferapply?/wfdynaexpgridview/:wfdynaexpgridview?',
            parameters: [
                { pathName: 'hrtransferapplies', parameterName: 'hrtransferapply' },
                { pathName: 'wfdynaexpgridview', parameterName: 'wfdynaexpgridview' },
            ],
        },
        {
            appfunctag: '_3',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrlegalgridview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrlegals/:hrlegal?/gridview/:gridview?',
            parameters: [
                { pathName: 'hrlegals', parameterName: 'hrlegal' },
                { pathName: 'gridview', parameterName: 'gridview' },
            ],
        },
        {
            appfunctag: '_5',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hremployeetabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hremployees/:hremployee?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hremployees', parameterName: 'hremployee' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
        {
            appfunctag: '_9',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrcertificatetabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrcertificates/:hrcertificate?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hrcertificates', parameterName: 'hrcertificate' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
        {
            appfunctag: '_11',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrcontracttabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrcontracts/:hrcontract?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hrcontracts', parameterName: 'hrcontract' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
        {
            appfunctag: '_7',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrtechnicaltitletabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrtechnicaltitles/:hrtechnicaltitle?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hrtechnicaltitles', parameterName: 'hrtechnicaltitle' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
        {
            appfunctag: '_15',
            appfuncyype: 'APPVIEW',
            openmode: '',
            codename: 'hrtransferapplytabexpview',
            deResParameters: [],
            routepath: '/pim/:pim?/hrtransferapplies/:hrtransferapply?/tabexpview/:tabexpview?',
            parameters: [
                { pathName: 'hrtransferapplies', parameterName: 'hrtransferapply' },
                { pathName: 'tabexpview', parameterName: 'tabexpview' },
            ],
        },
	];

	/**
	 * 根据当前路由查找激活菜单
	 *
	 * @param {*} route
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public findActiveMenuByRoute(route: any): any {
		if (route) {
			const func = this.funcs.find((item: any) => {
				if (item.openmode === '') {
					const url: string = ViewTool.buildUpRoutePath(route, route.params, [], item.parameters, [], {});
					return url === route.fullPath;
				}
			});
            if (func) {
			    return this.findMenuByFuncTag(func.appfunctag);
            }
		}
	}

	/**
	 * 根据应用功能id查找菜单项
	 *
	 * @param {string} tag
	 * @param {any[]} [menus=this.items]
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public findMenuByFuncTag(tag: string, menus: any[] = this.items): any {
		let menu: any;
		menus.every((item: any) => {
			if (item.appfunctag === tag) {
				menu = item;
				return false;
			}
			if (item.items) {
				menu = this.findMenuByFuncTag(tag, item.items);
				if (menu) {
					return false;
				}
			}
			return true;
		});
		return menu;
	}

	/**
	 * 查找默认打开菜单
	 *
	 * @param {any[]} [menus=this.items]
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public findDefaultOpenMenu(menus: any[] = this.items): any {
		let menu: any;
		menus.every((item: any) => {
			if (item.opendefault === true) {
				menu = item;
				return false;
			}
			if (item.items) {
				menu = this.findMenuByFuncTag(item.items);
				if (menu) {
					return false;
				}
			}
			return true;
		});
		return menu;
	}

    /**
     * 获取所有菜单项集合
     *
     * @returns {any[]}
     * @memberof PIMModel
     */
    public getAppMenuItems(): any[] {
        return this.items;
    }

	/**
	 * 根据名称获取菜单组
	 *
	 * @param {string} name
	 * @returns {*}
	 * @memberof PIMModel
	 */
	public getMenuGroup(name: string): any {
		return this.items.find((item: any) => Object.is(item.name, name));
	}

    /**
     * 获取所有应用功能集合
     *
     * @returns {any[]}
     * @memberof PIMModel
     */
    public getAppFuncs(): any[] {
        return this.funcs;
    }
}